home *** CD-ROM | disk | FTP | other *** search
/ Mac Magazin/MacEasy 32 / Mac Magazin and MacEasy Magazine CD - Issue 32.iso / Grafik & Text / OzTeX3.0 / MetaPost / Docs / mpintro.tex (.txt) < prev    next >
LaTeX Document  |  1996-09-08  |  41KB  |  777 lines

  1. %&LaTeX
  2. \documentstyle{article}
  3. \input epsf
  4. \author{John D. Hobby}
  5. \title{The MetaPost System}
  6. \font\textt=cmtex10
  7. \makeatletter
  8. \def\logo{\global\font\logo=logo10 at1\@ptsize\p@ \logo}
  9. \def\logosl{\global\font\logosl=logosl10 at1\@ptsize\p@ \logosl}
  10. \def\MF{{\ifdim \fontdimen\@ne\font >\z@ \def\logo{\logosl}\fi
  11.     {\logo META}\-{\logo FONT}}}
  12. \makeatother
  13. \def\descr#1{{\langle\hbox{#1}\rangle}}
  14. \def\lit#1{{\hbox{\textt#1}}}
  15. \def\okbreak{\vfil\penalty2000 \vfilneg}
  16. {\obeylines\obeyspaces\gdef\startverbatim{%
  17. \vcenter\bgroup\textt\catcode`\$=12\catcode`\}=12\catcode`\{=12\catcode`\_=12%
  18. \catcode`\\=12\catcode`\#=12\catcode`\^=12\catcode`\%=0%
  19. \obeyspaces\let =\ \obeylines\let^^M=\cr\halign\bgroup##\hfil}}
  20. \def\stopverbatim{\egroup\egroup}
  21. \begin{document}
  22. \maketitle
  23. \begin{abstract}
  24. The MetaPost system implements a picture-drawing language very much like Knuth's
  25. \MF\ except that it outputs PostScript commands instead of run-length-encoded
  26. bitmaps.  MetaPost is a powerful language for producing figures for documents
  27. to be printed on PostScript printers.  It provides easy access to all the
  28. features of PostScript and it includes facilities for integrating text and
  29. graphics.
  30. This document describes the system and its implementation.  It also includes
  31. basic user documentation to be used in conjunction with {\it The \MF book}.
  32. Much of the source code was copied from the \MF\ sources by permission from
  33. the author.
  34. \end{abstract}
  35. \section{Overview}
  36. The MetaPost system is based on Knuth's \MF\footnote{\MF\ is a trademark
  37. of Addison Wesley Publishing company.}~\cite{kn:c} and much of the source
  38. code is copied with permission from the \MF\ sources.  MetaPost is a graphics
  39. language like \MF, but with new primitives for integrating text and graphics and
  40. for accessing special features of PostScript\footnote{PostScript is a
  41. trademark of Adobe Systems Inc.} such as clipping, shading, and
  42. dashed lines.  The language has the main features of \MF\ including first-class
  43. objects for curves, pictures, affine transformations, and pen shapes.
  44. Another feature borrowed from \MF\ is the ability to solve linear equations
  45. that are given implicitly, thus allowing many programs to be written in a
  46. largely declarative style.
  47. While MetaPost could be used as a tool for generating PostScript fonts,
  48. the intended application is to generate figures for \TeX\footnote{\TeX\ is a
  49. trademark of the American Mathematical Society.} and {\it troff\/} documents.
  50. The figures can be integrated into a \TeX\ document via a freely available
  51. program called {\tt dvips} as shown in Figure~1.\footnote{The C source for
  52. {\tt dvips} comes with the web2c \TeX\ distribution. Similar programs are
  53. available from other sources.}  A similar procedure works with troff: the
  54. {\tt dpost} output processor includes PostScript figures when they are
  55. requested via troff's {\tt \char`\\X} command.
  56. \begin{figure}[htp]
  57. $$ \def\fbox#1{\hbox{\vrule
  58.     \vbox{\hrule\kern5pt\hbox{\kern5pt\hbox{#1}\kern5pt}\kern5pt\hrule}%
  59.     \vrule}}
  60.    \vbox{
  61.     \halign{$\hfil#\hfil$&\hskip1in$\hfil#\hfil$\cr
  62.     \hbox{Figures in MetaPost}&
  63.     \hbox{\TeX\ Document}
  64.     \bigg\downarrow&
  65.     \bigg\downarrow
  66.     \fbox{\vrule height.2in depth.133in width0pt
  67.         \kern .1in MetaPost\kern.1in}
  68.     \fbox{\vrule height.2in depth.133in width0pt
  69.         \kern .167in \TeX\kern.167in}
  70.     \bigg\downarrow&
  71.     \bigg\downarrow
  72.     \hbox{Figures in PostScript}&
  73.     \hbox{{\tt dvi} file}
  74.     \bigg\downarrow&
  75.     \bigg\downarrow
  76.     \fbox{\vrule height.2in depth.133in width0pt
  77.         \kern 1in {\tt dvips} \kern1in}
  78.     \span\omit\cr
  79.     \bigg\downarrow\span\omit\cr
  80.     \hbox{PostScript}\span\omit\cr}}
  81.    \atop
  82.    \vbox{\noindent Fig.~1: A diagram of the processing for a \TeX\ document with figures
  83.     done in Meta\-Post}
  84. \end{figure}
  85. Other than the new commands for integrating text and accessing features of
  86. PostScript, the main difference between the \MF\ and MetaPost languages is
  87. that the latter deals with continuous pictures rather than discrete ones.
  88. This affects the coordinate system and some of the subtler aspects of the
  89. language as outlined in the next two sections.
  90. Sections \ref{basic} and \ref{advanced} give a short summary of the language
  91. with numerous examples.  Then Section~\ref{impsec} describes the implementation.
  92. A preliminary description of the language has already appeared~\cite{ho:mp1}.
  93. \section{Introduction to MetaPost}
  94. \label{basic}
  95. MetaPost is a lot like Knuth's \MF\
  96. except that it outputs PostScript programs instead
  97. of bitmaps.  Knuth describes the \MF\ language in {\sl The \MF book\/}.~\cite{kn:d}
  98. This document introduces MetaPost via examples and references to key parts of
  99. {\sl The \MF book}.  It is a good idea to start by reading chapters 2~and 3
  100. in {\sl The \MF book}.  The introductory material in these chapters applies
  101. to MetaPost except that coordinates are in units of
  102. PostScript points by default (72 units per inch).
  103. To see MetaPost in action, consider a file \lit{fig.mp} containing the
  104. following text:\vadjust{\okbreak}
  105. $$ \startverbatim
  106. beginfig(1);
  107. a=.7in; b=0.5in;
  108. z0=(0,0); z1=(a,0); z2=(0,b);
  109. z0=.5[z1,z3]=.5[z2,z4];
  110. draw z1..z2..z3..z4..cycle;
  111. drawarrow z0..z1;
  112. drawarrow z0..z2;
  113. label.top(btex $a$ etex, .5[z0,z1]);
  114. label.lft(btex $b$ etex, .5[z0,z2]);
  115. endfig;
  116. %stopverbatim$$
  117. Then the command \lit{mp} \lit{fig} produces an output file \lit{fig.1}
  118. that can be included in a
  119. \TeX\ document.  After \lit{\string\input} \lit{epsf} the \TeX\ commands
  120. \lit{\$\$\string\epsfbox\char`\{fig.1\char`\}\$\$} produce
  121. $$ \epsfbox{examples.1} $$
  122. The \lit{beginfig(1)} line means that everything up to the next
  123. \lit{endfig} is to be used to create \lit{fig.1}.  If there
  124. were more than one figure in \lit{fig.mp}, there would be additional
  125. \lit{beginfig} $\ldots$ \lit{endfig} blocks.
  126. The \lit{drawarrow} macro has been specially developed for MetaPost.
  127. There is also a command called \lit{drawdblarrow} that draws the
  128. following path with arrowheads on both ends.  The line beginning with
  129. \lit{label.top} is a call to a standard macro for positioning text just
  130. above a given point.  In this case, the point \lit{.5[z0,z1]} is the
  131. midpoint of the segment from \lit{z0} to \lit{z1} and the text is
  132. generated by the \TeX\ commands \lit{\$a\$}.  In addition to \lit{label.top}
  133. and \lit{label.lft}, there is also \lit{label.bot}, \lit{label.rt},
  134. and four other versions \lit{label.ulft} for upper-left etc.  Just
  135. plain \lit{label} without any suffix centers the
  136. label on the given point.
  137. The discussion of pens in Chapter~4 of {\sl The \MF book\/} applies
  138. to MetaPost as well, but simple figures often do not need to refer to
  139. pens explicitly because they can just use the default pen which is a
  140. circle $0.5{\it bp}$ in diameter.\footnote{The letters ``{\it bp}''
  141. stand for ``big point'' ($1\over72$ inch).  This is one of the standard
  142. units of measure in \TeX\ and \MF\ and it is the default unit for
  143. MetaPost. A complete listing of predefined units is given on page~92 of
  144. {\sl The \MF book}.} This produces lines of uniform thickness
  145. $0.5{\it bp}$ regardless of the direction of the line.
  146. Chapter 5 of {\sl The \MF book\/} does not apply to MetaPost.
  147. In particular, there is no \lit{mode\_setup} macro or ``sharped units''
  148. and \lit{mp} does not output \lit{gf} files.  MetaPost does have
  149. a set of preloaded macros but they are not the same as \MF's plain base.
  150. If there were an
  151. analogous chapter about running MetaPost, it would probably mention that
  152. \lit{mp} skips over \lit{btex} $\ldots$ \lit{etex} blocks
  153. and depends on a preprocessor to translate them into low level MetaPost
  154. commands.  If the main file is \lit{fig.mp}, the translated \TeX\
  155. material is placed in a file named \lit{fig.mpx}.  This is normally
  156. done silently without any user intervention but it could fail if one of
  157. the \lit{btex} $\ldots$ \lit{etex} blocks contains an erroneous
  158. \TeX\ command.  If this happens, the erroneous \TeX\ input is saved in
  159. the file \lit{mpxerr.tex} and the error messages appear in
  160. \lit{mpxerr.log}.
  161. If there is a need for \TeX\ macro definitions or any other auxiliary
  162. \TeX\ commands, they can be enclosed in a
  163. \lit{verbatimtex} $\ldots$ \lit{etex} block.  The difference between
  164. \lit{btex} and \lit{verbatimtex} is that the former generates a picture
  165. expression while the latter does not.
  166. On Unix systems, an environment variable can be used to specify that
  167. \lit{btex} $\ldots$ \lit{etex} and \lit{verbatimtex} $\ldots$ \lit{etex}
  168. blocks are in {\it troff\/} instead of \TeX.  When using this option,
  169. it is a good idea to give the MetaPost command \lit{prologues:=1}.
  170. This tells \lit{mp} to output structured PostScript and assume that
  171. text comes from built-in PostScript fonts.
  172. Chapters 6--10 of {\sl The \MF book\/} cover important aspects of \MF\
  173. that are almost identical in MetaPost.  The only change to the tokenization
  174. process described in Chapter~6 is that \TeX\ material can contain
  175. percent signs and unmatched double quote characters so these are
  176. treated like spaces when skipping \TeX\ material.  The preprocessor gives
  177. \TeX\ everything between \lit{btex} and \lit{etex} except for leading
  178. and trailing spaces.
  179. Chapters 7--10 discuss the types of variables and expressions that \MF\
  180. understands.  MetaPost has an additional type ``\lit{color}'' that is
  181. a lot like \lit{pair} except that it has three components instead of
  182. two.  The operations allowed on colors are addition, subtraction, scalar
  183. multiplication, and scalar division.  MetaPost also understands mediation
  184. expressions involving colors since
  185. \lit{.3[w,b]} is equivalent to \lit{w+.3(b-w)} which is allowed
  186. even when \lit{w} and \lit{b} are colors.  Colors can be specified
  187. in terms of the predefined constants \lit{black}, \lit{white},
  188. \lit{red}, \lit{green}, \lit{blue}, or the red, green, and blue
  189. components can be given explicitly.  Black is \lit{(0,0,0)} and white
  190. is \lit{(1,1,1)}.  There is no restriction against colors ``blacker
  191. than black'' or ``whiter than white'' except all components are snapped
  192. back to the $[0,1]$ range when a color is given in an output file.
  193. MetaPost solves linear equations involving colors the same way it does
  194. so for pairs.  (This is explained in Chapter~9).
  195. Let's consider another example that uses some of the ideas discussed above.
  196. The MetaPost program\vadjust{\okbreak}
  197. $$ \startverbatim
  198. beginfig(2);
  199. h=2in; w=2.7in;
  200. path p[], q[], pp;
  201. for i=1.5,2,4: ii:=i**2;
  202.   p[i] = (w/ii,h){1/ii,-1}...(w/i,h/i)...(w,h/ii){1,-1/ii};
  203. endfor
  204. for i=.5,1.5: q[i] = origin..(w,i*h) cutafter p1.5; endfor
  205. pp = buildcycle(q0.5, p2, q1.5, p4);
  206. fill pp withcolor .8white;
  207. z0=center pp;
  208. picture lab; lab=thelabel(btex $f>0$ etex, z0);
  209. unfill bbox lab; draw lab;
  210. draw q0.5; draw p2; draw q1.5; draw p4;
  211. makelabel.top(btex $P$ etex, p2 intersectionpoint q0.5);
  212. makelabel.rt(btex $Q$ etex, p2 intersectionpoint q1.5);
  213. endfig;
  214. %stopverbatim$$
  215. produces the following figure:\vadjust{\okbreak}
  216. $$ \epsfbox{examples.2} $$
  217. The third line declares arrays of paths \lit{p} and \lit{q} as explained
  218. in Chapter~7.  Note that \lit{q1.5} is the same as \lit{q[i]} when
  219. $\lit{i}=1.5$.  The \lit{for} loops make each \lit{p[i]}
  220. an approximation to an arc of the hyperbola
  221. $$xy={wh\over i^2} $$
  222. and each \lit{q[i]} a segment of slope $ih/w$.  (Loops are discussed in
  223. Chapter~19 of {\sl The \MF book\/}).
  224. The \lit{cutafter} operator is used to cut off the part of \lit{q[i]} after
  225. the intersection with \lit{p1.5}.  (There is no ``\lit{draw} \lit{p1.5}'' in
  226. the input for the above figure so this hyperbola is invisible).  There is also a
  227. \lit{cutbefore} operator defined to make
  228. $$ a \lit{ cutbefore } b $$
  229. what's left of path~$a$ when everything before its intersection with~$b$ is
  230. removed.  In case of multiple intersections \lit{cutbefore} and \lit{cutafter}
  231. try to cut off as little as possible.
  232. The shaded region in the above figure is due to the line
  233. $$ \lit{fill pp withcolor .8white} $$
  234. The boundary of this region is the path \lit{pp} that the \lit{buildcycle}
  235. macro creates by piecing together the four paths given as arguments.  In other
  236. words, \lit{pp} is constructed by going along \lit{q0.5} until it
  237. intersects \lit{p2}, then going along \lit{p2} until hitting
  238. \lit{q1.5}, etc.  It turns out that this requires going backwards along
  239. \lit{p2} and \lit{q1.5}.  The \lit{buildcycle} macro tries to avoid
  240. going backwards if it has a choice as to which intersection points to choose,
  241. but in this example each pair of consecutive path arguments has a unique
  242. intersection point.  It is generally a good idea to avoid multiple intersections
  243. because they can lead to unpleasant surprises.
  244. The \lit{fill} and \lit{unfill} macros in plain MetaPost are similar to
  245. the corresponding macros discussed in Chapter~13 of {\sl The \MF book\/}
  246. but MetaPost assigns colors to regions rather than assigning weights to pixels.
  247. There is no \lit{cull} command or \lit{withweight} option in MetaPost.
  248. The \lit{unfill} macro used to erase the rectangle containing the label
  249. ``$f>0$'' in the above figure works by specifying ``\lit{withcolor}
  250. \lit{background}''
  251. where \lit{background}'' is usually equal to \lit{white}.  The complete
  252. syntax for primitive drawing commands in MetaPost is as follows:
  253. $$\tabskip=0.0pt plus 1000.0pt minus 1000.0pt
  254.   \halign to\hsize{$#$\hfil\cr
  255.   \descr{picture command} \rightarrow
  256.      \descr{addto command} \mid \descr{clip command} \cr
  257.   \descr{addto command} \rightarrow {} \cr
  258.   \qquad \lit{addto }\descr{picture variable} \lit{ also }
  259.      \descr{picture expression} \descr{with list} \cr
  260.   \qquad {}\mid \lit{addto } \descr{picture variable} \lit{ contour }
  261.      \descr{path expression} \descr{with list} \cr
  262.   \qquad {}\mid \lit{addto } \descr{picture variable} \lit{ doublepath }
  263.      \descr{path expression} \descr{with list} \cr
  264.   \descr{with list} \rightarrow \descr{empty} \mid
  265.      \descr{with clause} \descr{with list} \cr
  266.   \descr{with clause} \rightarrow \lit{withcolor } \descr{color expression}\cr
  267.   \qquad {} \mid \lit{withpen } \descr{pen expression}
  268.      \mid \lit{dashed } \descr{picture expression}\cr
  269.   \descr{clip command} \rightarrow \lit{clip }
  270.      \descr{picture variable} \lit{ to } \descr{path expression} \cr}
  271. If $P$ stands for \lit{currentpicture}, $q$ stands for
  272. \lit{currentpen}, and $b$ stands for \lit{background}, the standard
  273. drawing macros have roughly the following meanings:
  274. $$ \tabskip=0.0pt plus 1000.0pt minus 1000.0pt
  275.   \halign to\hsize{$#$\hfil&\quad means\quad $#$\hfil\cr
  276.   \lit{draw }p&        \lit{addto }P\lit{ doublepath }p\lit{ withpen }q\cr
  277.   \lit{fill }c&        \lit{addto }P\lit{ contour }c\cr
  278.   \lit{filldraw }c&    \lit{addto }P\lit{ contour }c\lit{ withpen }q\cr
  279.   \lit{undraw }p&        \lit{addto }P\lit{ doublepath }p\lit{ withpen }q
  280.     \lit{ withcolor }b\cr
  281.   \lit{unfill }c&        \lit{addto }P\lit{ contour }c\lit{ withcolor }b\cr
  282.   \lit{unfilldraw }c&    \lit{addto }P\lit{ contour }c\lit{ withpen }q
  283.     \lit{ withcolor }b\cr}
  284. The expressions denoted by $c$ in the table must be cyclic paths, while path
  285. expressions $p$ need not be cyclic.  It is also possible to use \lit{draw}
  286. and \lit{undraw} when the argument is a picture~$r$:
  287. $$ \tabskip=0.0pt plus 1000.0pt minus 1000.0pt
  288.   \halign to\hsize{$#$\hfil&\quad means\quad $#$\hfil\cr
  289.   \lit{draw }r&        \lit{addto }P\lit{ also }r\cr
  290.   \lit{undraw }r&    \lit{addto }P\lit{ also }r\lit{ withcolor }b\cr}
  291. The argument to \lit{unfill} in the last example is \lit{bbox lab}.
  292. This is a call to a standard macro that gives the bounding box of a picture
  293. as a rectangular path.  The \lit{center} macro used two lines previously
  294. makes \lit{z0} the center of the bounding box for path \lit{pp}.  (This
  295. works for paths and pictures).  The expression
  296. $$ \lit{thelabel(btex \$f>0\$ etex, z0)} $$
  297. computes a picture containing the text ``$f>0$'' centered on the point
  298. \lit{z0}.
  299. Here is the complete syntax for labeling commands:
  300. $$\tabskip=0.0pt plus 1000.0pt minus 1000.0pt
  301.   \halign to\hsize{$#$\hfil\cr
  302.   \descr{label command} \rightarrow
  303.     \descr{command name} \descr{position suffix}
  304.     (\descr{label text},\ \descr{label loc}) \cr
  305.   \qquad {}\mid \lit{labels} \descr{position suffix} (\descr{suffix list}) \cr
  306.   \descr{command name} \rightarrow \lit{label}
  307.     \mid \lit{thelabel} \mid \lit{makelabel} \cr
  308.   \descr{position suffix} \rightarrow
  309.     \descr{empty} \mid \lit{.lft} \mid \lit{.rt} \mid \lit{.top}
  310.     \mid \lit{.bot} \cr
  311.   \qquad {}\mid \lit{.ulft} \mid \lit{.urt} \mid \lit{.llft}
  312.     \mid \lit{.lrt}\cr
  313.   \descr{label text} \rightarrow \descr{picture expression}
  314.     \mid \descr{string expression} \cr
  315.   \descr{label loc} \rightarrow \descr{pair expression} \cr
  316.   \descr{suffix list} \rightarrow \descr{suffix}
  317.     \mid \descr{suffix}, \descr{suffix list} \cr}
  318. The \lit{label} command adds text to \lit{currentpicture} near the
  319. position $\descr{label loc}$ as determined by the $\descr{position suffix}$.
  320. An empty suffix centers the label and the other options offset it slightly so
  321. that it does not overlap the $\descr{label loc}$.  Using \lit{thelabel} just
  322. creates a picture expression rather than actually adding it to
  323. \lit{currentpicture}. Using \lit{makelabel} instead of \lit{label} adds a dot
  324. at the location being labeled.  Finally, the \lit{labels}
  325. command does
  326. $$ \lit{makelabel} \descr{position suffix}
  327.     (\lit{str}\,\descr{suffix},\,\lit{z}\descr{suffix})
  328. for each $\descr{suffix}$ in the $\descr{suffix list}$, using the \lit{str}
  329. operator to convert the suffix to a string.  Thus \lit{labels.top(1,2a)} places
  330. labels ``\lit{1}'' and ``\lit{2a}'' just above \lit{z1} and \lit{z2a}.
  331. The examples given so far have all used $\descr{label text}$ of the form
  332. $$ \lit{btex}\ \descr{\TeX\ commands}\ \lit{etex}.
  333. This gets converted into a picture expression.  If the label is simple enough,
  334. it can be given directly as a string expression in which case it is typeset
  335. in \lit{defaultfont} at \lit{defaultscale} times its design size.
  336. Normally,
  337. $$ \lit{defaultfont="cmr10"}
  338.    \quad{\rm and}\quad \lit{defaultscale=1},
  339. but these can be reset if desired.  Using \lit{cmtex10} instead of
  340. \lit{cmr10} would allow the label to contain spaces and special characters.
  341. If there is any doubt about what the design size is, use the \lit{fontsize}
  342. operator to find it as follows:
  343. $$ \lit{defaultfont:="Times";}
  344.    \qquad \lit{defaultscale:=10/fontsize "Times"}
  345. Notice that a $\descr{with clause}$ can be
  346. ``\lit{dashed} $\descr{picture expression}$.''  The picture
  347. gives a template that tells how the line being drawn is to be dashed.  There
  348. is a standard template called \lit{evenly} that makes dashes $3bp$ long
  349. separated by gaps of length $3bp$.  It is possible to scale the template in
  350. order to get a finer or coarser pattern.  Thus
  351. $$ \lit{draw z1..z2 dashed evenly scaled 2} $$
  352. draws a line with dashes $6bp$ long with gaps of $6bp$.
  353. The following MetaPost input illustrates the use of dashed
  354. lines:\vadjust{\okbreak}
  355. $$ \startverbatim
  356. beginfig(3);
  357. 3.2scf = 2.4in;
  358. path fun;
  359. # = .1;
  360. fun = ((0,-1#)..(1,.5#){right}..(1.9,.2#){right}
  361.        ..{curl .1}(3.2,2#))  scaled scf yscaled(1/#);
  362. vardef vertline primary x = (x,-infinity)..(x,infinity) enddef;
  363. primarydef f atx x = (f intersectionpoint vertline x) enddef;
  364. primarydef f whenx x = xpart(f intersectiontimes vertline x)
  365.   enddef;
  366. z1a = (2.5scf,0);
  367. z1 = fun atx x1a;
  368. y2a=0; z1-z2a=whatever*direction fun whenx x1 of fun;
  369. z2 = fun atx x2a;
  370. y3a=0; z2-z3a=whatever*direction fun whenx x2 of fun;
  371. draw fun withpen pencircle scaled 1pt;
  372. drawarrow (0,0)..(3.2scf,0);
  373. label.bot(btex $x_1$ etex, z1a);
  374. draw z1a..z1 dashed evenly;
  375. makelabel(nullpicture, z1);
  376. draw z1..z2a withpen pencircle scaled .3;
  377. label.bot(btex $x_2$ etex, z2a);
  378. draw z2a..z2 dashed evenly;
  379. makelabel(nullpicture, z2);
  380. draw z2..z3a withpen pencircle scaled .3;
  381. label.bot(btex $x_3$ etex, z3a);
  382. endfig;
  383. %stopverbatim$$
  384. This produces the following figure:\vadjust{\okbreak}
  385. $$ \epsfbox{examples.3} $$
  386. The above figure uses some of the more advanced properties of paths discussed
  387. in Chapter~14 of {\sl The \MF book}.  All of this material applies to
  388. MetaPost as well as \MF\ except for the explanation of ``strange paths'' which
  389. fortunately cannot occur in MetaPost.  The parts most relevant to this figure
  390. are the explanation of ``curl'' specifications and the \lit{direction},
  391. \lit{intersectiontimes}, and \lit{intersectionpoint} operators.
  392. In order to ensure that the path \lit{fun} makes $y$ a unique function
  393. of~$x$, the path is first constructed with the $y$-coordinates compressed
  394. by a factor of ten.  The final ``\lit{yscaled(1/\char`\#)}'' restores
  395. the original aspect ratio after MetaPost has chosen a cubic spline that
  396. interpolates the given points.
  397. The \lit{yscaled} operator is an example of a very important class of
  398. operators that apply affine transformations to pairs, paths, pens, pictures,
  399. and other transforms.  The discussion in Chapter~15 is relevant and
  400. important.  The only differences are that MetaPost has no
  401. {\it currenttransform} and there is no restriction on the type of
  402. transformations that can be applied to pictures.
  403. \section{More Advanced Topics}
  404. \label{advanced}
  405. MetaPost does have pens like those in \MF\ but they aren't very important
  406. to the casual user except occasionally to specify changes in line widths
  407. as in the preceding figure.  Anyone reading the description in Chapter~16 of
  408. {\sl The \MF book} should beware that there is no such thing as a
  409. ``future pen'' in MetaPost and elliptical pens are never converted into
  410. polygons.  Furthermore, there is no need for \lit{cutoff} and
  411. \lit{cutdraw} because the same effect can be achieved by setting the
  412. internal parameter \lit{linecap:=butt}.\vadjust{\okbreak}
  413. $$\startverbatim
  414. beginfig(4);
  415. for i=0 upto 2:
  416.   z[i]=(0,40i); z[i+3]-z[i]=(100,30);
  417. endfor
  418. pickup pencircle scaled 18;
  419. def gray = withcolor .8white enddef;
  420. draw z0..z3 gray;
  421. linecap:=butt; draw z1..z4 gray;
  422. linecap:=squared; draw z2..z5 gray;
  423. labels.top(0,1,2,3,4,5);
  424. endfig; linecap:=rounded;
  425. %stopverbatim
  426. \qquad
  427. \vcenter{\epsfbox{examples.4}}
  428. There is also a \lit{linejoin} parameter as illustrated below.
  429. The default values of \lit{linecap} and \lit{linejoin} are both
  430. \lit{rounded}.\vadjust{\okbreak}
  431. $$ \startverbatim
  432. beginfig(5);
  433. for i=0 upto 2:
  434.   z[i]=(0,50i); z[i+3]-z[i]=(60,40);
  435.   z[i+6]-z[i]=(120,0);
  436. endfor
  437. pickup pencircle scaled 24;
  438. def gray = withcolor .8white enddef;
  439. draw z0--z3--z6 gray;
  440. linejoin:=mitered; draw z1..z4--z7 gray;
  441. linejoin:=beveled; draw z2..z5--z8 gray;
  442. labels.bot(0,1,2,3,4,5,6,7,8);
  443. endfig; linejoin:=rounded;
  444. %stopverbatim
  445. \qquad
  446. \vcenter{\epsfbox{examples.5}}
  447. \mskip-54mu % allow it to hang into the margin
  448. Another way to adjust the behavior of drawing commands is by giving the
  449. declaration
  450. $$ \lit{drawoptions}(\descr{with list}) $$
  451. For instance,
  452. $$ \lit{drawoptions(withcolor blue)} $$
  453. gives subsequent drawing commands the default color blue.  This can still
  454. be overridden by giving another \lit{withcolor} clause as in
  455. $$ \lit{draw p withcolor red} $$
  456. The options apply only to relevant drawing commands:
  457. $$ \lit{drawoptions(dashed dd)} $$
  458. will affect \lit{draw} commands but not fill commands.
  459. Chapters 17--20 of {\sl The \MF book} describe the programming constructs
  460. necessary to customize the language to a particular problem.  These features
  461. work the same way in MetaPost but a few additional comments are needed.
  462. These chapters mention certain macros from plain \MF\ that are not in the
  463. plain macro package for MetaPost.  Generally if it sounds as though it's
  464. for making fonts, MetaPost doesn't have it.  Remember that \lit{beginfig}
  465. and \lit{endfig} play the role of \MF's \lit{beginchar} and \lit{endchar}.
  466. Look in the file \lit{plain.mp} in the standard macro area if there is any
  467. doubt about what macros are predefined.  This file is also a good source of
  468. examples.
  469. Chapter 17 explains how the \lit{interim} statement makes temporary changes
  470. to internal quantities.  This works the same way in MetaPost except that
  471. the example involving {\it autorounding} is inappropriate because MetaPost
  472. doesn't have that particular quantity.  Here is a complete list of the
  473. internal quantities found in \MF\ but not MetaPost:
  474. $$\vcenter{\hsize=.8\hsize \raggedright \multiply\rightskip by3 \textt\noindent
  475.     \lit{autorounding}, \lit{fillin}, \lit{granularity}, \lit{hppp},
  476.     \lit{proofing}, \lit{smoothing}, \lit{tracingedges},
  477.     \lit{tracingpens}, \lit{turningcheck}, \lit{vppp}, \lit{xoffset},
  478.     \lit{yoffset}}
  479. The following additional quantities are defined in plain \MF\ but not in
  480. plain MetaPost:
  481. $$\vcenter{\hsize=.8\hsize \raggedright \multiply\rightskip by3 \textt\noindent
  482.     \lit{pixels\_per\_inch}, \lit{blacker}, \lit{o\_correction},
  483.     \lit{displaying}, \lit{screen\_rows}, \lit{screen\_cols},
  484.     \lit{currentwindow}}
  485. There are also some internal quantities that are unique to MetaPost.
  486. The \lit{linecap} and \lit{linejoin} parameters have already been mentioned.
  487. There is also a \lit{miterlimit} parameter that behaves like the similarly
  488. named parameter in PostScript.  Another parameter, \lit{tracing\_lost\_chars}
  489. suppresses error messages about attempts to typeset missing characters.
  490. This is probably only relevant when using string parameters in the labeling
  491. macros since expressions generated by \lit{btex} $\ldots$ \lit{etex}
  492. blocks are not likely to use missing characters.
  493. The \lit{prologues} parameter was referred to earlier when we recommended
  494. setting it to one when including MetaPost output in a {\it troff\/} document.
  495. Any positivie value causes the output files to be ``conforming PostScript''
  496. that assumes only standard Adobe fonts are used.  This makes the output
  497. more portable but on most implementations, it precludes the use of the use
  498. of \TeX\ fonts such as \lit{cmr10}.  Software for sending \TeX\ output to
  499. PostScript printers generally downloads such fonts one character at a time
  500. and does not make them available in included PostScript figures.
  501. Plain MetaPost also has
  502. internals \lit{bboxmargin}, \lit{labeloffset} and \lit{ahangle}
  503. as well as \lit{defaultscale} which controls the size of the default label
  504. font as explained above.  The \lit{bboxmargin} parameter is the amount of
  505. extra space that the \lit{bbox} operator leaves; \lit{labeloffset} gives the
  506. distance by which labels are offset from the point being labeled;
  507. \lit{ahangle} is the angle of the pointed ends of arrowheads
  508. ($45^\circ$ by default).  There is also a path \lit{ahcirc} that controls
  509. the size of the arrowheads.  The statement
  510. $$ \lit{ahcirc := fullcircle scaled d} $$
  511. changes the arrowhead length to $\lit{d}/2$.
  512. The only relevant new material in {\sl The \MF book\/} not mentioned so far
  513. is in Chapters 21--22 and Appendix~D.  Chapters 23 and~24 do not apply to
  514. MetaPost at all.  The grammar given in Chapters 25 and~26 isn't exactly a
  515. grammar of MetaPost, but most of the differences have been mentioned above.
  516. There are \lit{redpart}, \lit{bluepart}, and \lit{greenpart} operators for
  517. colors and there is no \lit{totalweight} operator.  The new primitive for
  518. label text in pictures is
  519. $$ \descr{picture secondary} \rightarrow
  520.     \descr{picture secondary} \lit{ infont } \descr{string primary}
  521. Bounding box information can be obtained via the operators
  522. \begin{eqnarray*}
  523.   \descr{pair primary} &\rightarrow& \descr{corner selector}
  524.     \descr{picture primary}\\
  525.   \descr{corner selector} &\rightarrow& \lit{llcorner} \mid \lit{urcorner}
  526.     \mid \lit{lrcorner} \mid \lit{urcorner}
  527. \end{eqnarray*}
  528. The main reason for having these in the MetaPost language is for measuring
  529. text but they work for pictures containing any mixture of text and graphics.
  530. The command
  531. $$ \lit{special }\descr{string expression} $$
  532. adds a line of text at the beginning of the next output file.  For instance,
  533. the following commands add PostScript definitions that allow MetaPost output
  534. to use the built-in font \lit{Times-Roman}.
  535. $$ \startverbatim
  536. special "/Times-Roman /Times-Roman def";
  537. special "/fshow {exch findfont exch scalefont setfont show}";
  538. special " bind def";
  539. %stopverbatim
  540. A similar definition is generated automatically when you set \lit{prologues:=1}.
  541. With \lit{prologues=0}, it is assumed that the program that translates \TeX\
  542. output and includes PostScript figures will add the necessary definition.%
  543. \footnote{A full description of how to avoid including your
  544. output in a \TeX\ document is beyond the scope of this documentation.
  545. MetaPost output generated with \lit{prologues:=1} can be sent directly to a
  546. PostScript printer if it uses only built-in fonts like \lit{Helvetica}.}
  547. Another new feature of MetaPost that needs further explanation is the idea of
  548. a dash pattern.  It is easiest if you can just get by with the dash pattern
  549. called \lit{evenly} that is defined in plain MetaPost, but it seems necessary
  550. to give the exact rules just in case they are needed.
  551. A dash pattern is a picture containing one or more horizontal
  552. line segments.  It doesn't matter what pen is used to draw the line segments.
  553. MetaPost behaves as though the dash pattern is replicated to form an
  554. infinitely long horizontal dashed line to be used as a template for dashed
  555. lines.  For example, the following commands create a dash pattern~\lit{dd}:
  556. $$\startverbatim
  557. draw (1,0)..(3.0); draw (5,0)..(6,0);
  558. picture dd; dd=currentpicture; clearit;
  559. %stopverbatim
  560. Lining up an infinite number of copies of \lit{dd} produces a set of line
  561. segments
  562. $$ \{\,(5i,0)\ldots(5i+3,0) \mid \hbox{for all integer $i$}\,\}. $$
  563. This template is used by starting from the $y$-axis and going to the right,
  564. producing dashes $3bp$ long separated by gaps of length $2bp$.
  565. In this example, successive copies of \lit{dd} are offset by $5bp$ because
  566. the range of $x$ coordinates covered by the line segments in \lit{dd} is
  567. $6-1$ or $5bp$.  The offset can be increased by shifting the dash pattern
  568. vertically so that it lies at a $y$-coordinate greater that $5bp$ in
  569. absolute value.  The rule is that the horizontal offset between copies of
  570. the dash pattern is the maximum of $|y|$ and the range of $x$-coordinates.
  571. \bigbreak
  572. \centerline{\bf Making Boxes}
  573. \nobreak\medskip
  574. There are auxiliary macros not included in plain MetaPost that make it
  575. convenient to do things that {\it pic} is good at.  What follows
  576. is a description of how to use the macros contained in the file \lit{boxes.mp}.
  577. This may be of some interest to users who don't need these macros but want to
  578. see additional examples of what can be done in MetaPost.
  579. The main idea is that one should say
  580. $$ \lit{boxit} \descr{suffix}(\descr{picture expression}) $$
  581. in order to create pair variables $\descr{suffix}\lit{.c}$,
  582. $\descr{suffix}\lit{.n}$, $\descr{suffix}\lit{.e}$, etc.  These can then be
  583. used for positioning the picture before drawing it with a separate command such
  584. $$ \lit{drawboxed}(\descr{suffix}) $$
  585. The command \lit{boxit.bb(pic)} makes \lit{bb.c} the position where the center
  586. of picture \lit{pic} is to be placed and defines \lit{bb.sw}, \lit{bb.se},
  587. \lit{bb.ne}, and \lit{bb.nw} to be the corners of a rectangular path that will
  588. surround the resulting picture.  Variables \lit{bb.dx} and \lit{bb.dy} give
  589. the spacing between the shifted version of \lit{pic} and the surrounding
  590. rectangle and \lit{bb.off} is the amount by which \lit{pic} has to be shifted
  591. to achieve all this.
  592. The \lit{boxit} macro gives linear equations that force \lit{bb.sw},
  593. \lit{bb.se}, $\ldots$ to be the corners of a rectangle aligned on the $x$ and
  594. $y$ axes with the picture \lit{pic} centered inside.  The values of \lit{bb.dx},
  595. \lit{bb.dy}, and \lit{bb.c} are left unspecified so that the user can give
  596. equations for positioning the boxes.  If no such equations are given, macros
  597. such as \lit{drawbox} can detect this and give default values.\vadjust{\okbreak}
  598. $$ \epsfbox{examples.6} $$
  599. \okbreak
  600. The following example shows how this works in practice.
  601. $$ \startverbatim
  602. input boxes
  603. beginfig(7); boxjoin(a.se=b.sw; a.ne=b.nw);
  604. boxit.a(btex $\cdots$ etex);    boxit.ni(btex $n_i$ etex);
  605. boxit.di(btex $d_i$ etex);      boxit.nii(btex $n_{i+1}$ etex);
  606. boxit.dii(btex $d_{i+1}$ etex); boxit.aa(pic_.a);
  607. boxit.nk(btex $n_k$ etex);      boxit.dk(btex $d_k$ etex);
  608. di.dy = 2;
  609. drawboxed(a,ni,di,nii,dii,aa,nk,dk); label.lft("ndtable:", a.w);
  610. boxjoin(a.sw=b.nw; a.se=b.ne);
  611. interim defaultdy:=7;
  612. boxit.ba(); boxit.bb(); boxit.bc();
  613. boxit.bd(btex $\vdots$ etex); boxit.be(); boxit.bf();
  614. bd.dx=8; ba.ne=a.sw-(15,10);
  615. drawboxed(ba,bb,bc,bd,be,bf); label.lft("hashtab:",ba.w);
  616. def ndblock suffix $ =
  617.   boxjoin(a.sw=b.nw; a.se=b.ne);
  618.   forsuffixes $$=$a,$b,$c: boxit$$(); ($$dx,$$dy)=(5.5,4);
  619.   endfor; enddef;
  620. ndblock nda;  ndblock ndb;  ndblock ndc;
  621. nda.a.c-bb.c = ndb.a.c-nda.c.c = (whatever,0);
  622. xpart ndb.c.se = xpart ndc.a.ne = xpart di.c;
  623. ndc.a.c - be.c = (whatever,0);
  624. drawboxes(nda.a,nda.b,nda.c,ndb.a,ndb.b,ndb.c,ndc.a,ndc.b,ndc.c);
  625. drawarrow bb.c .. nda.a.w;
  626. drawarrow be.c .. ndc.a.w;
  627. drawarrow nda.c.c .. ndb.a.w;
  628. drawarrow nda.a.c{right}..{curl0}ni.c cutafter bpath ni;
  629. drawarrow nda.b.c{right}..{curl0}di.c cutafter bpath di;
  630. drawarrow ndc.a.c{right}..{curl0}nii.c cutafter bpath nii;
  631. drawarrow ndc.b.c{right}..{curl0}dii.c cutafter bpath dii;
  632. drawarrow ndb.a.c{right}..nk.c cutafter bpath nk;
  633. drawarrow ndb.b.c{right}..dk.c cutafter bpath dk;
  634. x.ptr=xpart aa.c;   y.ptr=ypart ndc.a.ne;
  635. drawarrow subpath (0,.7) of (z.ptr..{left}ndc.c.c);
  636. label.rt(btex ndblock etex, z.ptr); endfig;
  637. %stopverbatim
  638. It is instructive to compare the MetaPost output below with the similar figure
  639. in the {\it pic} manual \cite{ke:pic}.\vadjust{\okbreak}
  640. $$ \epsfbox{examples.7} $$
  641. The second line of input for the above figure contains
  642. $$ \lit{boxjoin(a.se=b.sw; a.ne=b.nw)} $$
  643. This causes boxes to line up horizontally by giving additional equations that
  644. are invoked each time some box \lit{a} is followed by some other box~\lit{b}.
  645. These equations are first invoked on the next line when box~\lit{a} is followed
  646. by box~\lit{ni}.  This yields
  647. $$ \lit{a.se=ni.sw; a.ne=ni.nw} $$
  648. The next pair of boxes is box~\lit{ni} and box~\lit{di}. This time the
  649. implicitly generated equations are
  650. $$ \lit{ni.se=di.sw; ni.ne=di.nw} $$
  651. This process continues until a new \lit{boxjoin} is given.  In this case the
  652. new declaration is
  653. $$ \lit{boxjoin(a.sw=b.nw; a.se=b.ne)} $$
  654. which causes boxes to be stacked below each other.
  655. After calling \lit{boxit} for the first eight boxes \lit{a} through \lit{dk},
  656. the example gives the single equation $\lit{di.dy}=2$ followed by a call to
  657. \lit{drawboxed} that draws the eight boxes with the given text inside of them.
  658. The equation forces there to be $2bp$ of space above and below the contents
  659. of box~\lit{di} (the label ``$d_i$'').  Since this doesn't fully specify the
  660. sizes and positions of the boxes, the \lit{drawboxed} macro starts by
  661. selecting default values, setting \lit{a.dx} through \lit{dk.dx} equal to
  662. the default value of $3bp$.
  663. The argument to boxit can be omitted as in \lit{boxit.ba()}
  664. or \lit{boxit.bb()}.  This is like calling \lit{boxit} with an empty picture.
  665. Alternatively the argument can be a string expression instead of a picture
  666. expression in which case the string is typeset in the default font.
  667. In addition to the corner points \lit{a.sw}, \lit{a.se}, $\ldots$, a command
  668. like \lit{boxit.a} defines points \lit{a.w}, \lit{a.s}, \lit{a.e} and
  669. \lit{a.n} at the midpoints of the outer rectangle.
  670. If this bounding rectangle is needed for something other than just being drawn
  671. by the \lit{drawboxed} macro, it can be referred to as \lit{bpath.a} or in
  672. general
  673. $$ \lit{bpath} \descr{box name} $$
  674. The \lit{bpath} macro is used in the arguments to \lit{drawarrow} in the
  675. previous example.  For instance
  676. $$ \lit{nda.a.c\char`\{right\char`\}..\char`\{curl0\char`\}ni.c} $$
  677. is a path from the center of box \lit{nda.a} to the center of box \lit{ni}.
  678. Following this with ``\lit{cutafter} \lit{bpath.ni}'' makes the arrow
  679. go towards the center of the box but stop when it hits the outer rectangle.
  680. The next example also uses this technique of cutting connecting arrows when
  681. they hit a bounding path, but in this case the bounding paths are circles
  682. and ovals instead of rectangles.  The circles and ovals are created by using
  683. \lit{circleit} in place of \lit{boxit}.  Saying \lit{circleit.a(pic)}
  684. defines points \lit{a.c}, \lit{a.s}, \lit{a.e}, \lit{a.n}, \lit{a.w}
  685. and distances \lit{a.dx} and \lit{a.dy}.  These variables describe how the
  686. picture is centered in an oval as can be seen from the following
  687. diagram:\vadjust{\okbreak}
  688. $$ \epsfbox{examples.8} $$
  689. \okbreak
  690. Here is the input for the figure that uses \lit{circleit}:
  691. $$\startverbatim
  692. beginfig(9);
  693. vardef cuta(suffix a,b) expr p =
  694.   drawarrow p cutbefore bpath.a cutafter bpath.b;
  695.   point .5*length p of p
  696. enddef;
  697. vardef self@# expr p =
  698.   cuta(@#,@#) @#.c{curl0}..@#.c+p..{curl0}@#.c  enddef;
  699. verbatimtex
  700.   \def\stk#1#2{$\displaystyle{\matrix{#1\cr#2\cr}}$} etex
  701. circleit.aa("Start"); aa.dx=aa.dy;
  702. circleit.bb(btex \stk B{(a|b)^*a} etex);
  703. circleit.cc(btex \stk C{b^*} etex);
  704. circleit.dd(btex \stk D{(a|b)^*ab} etex);
  705. circleit.ee("Stop"); ee.dx=ee.dy;
  706. numeric hsep;
  707. bb.c-aa.c = dd.c-bb.c = ee.c-dd.c = (hsep,0);
  708. cc.c-bb.c = (0,.8hsep);
  709. xpart(ee.e - aa.w) = 3.8in;
  710. drawboxed(aa,bb,cc,dd,ee);
  711. label.ulft(btex$b$etex, cuta(aa,cc) aa.c{dir50}..cc.c);
  712. label.top(btex$b$etex, self.cc(0,30pt));
  713. label.rt(btex$a$etex, cuta(cc,bb) cc.c..bb.c);
  714. label.top(btex$a$etex, cuta(aa,bb) aa.c..bb.c);
  715. label.llft(btex$a$etex, self.bb(-20pt,-35pt));
  716. label.top(btex$b$etex, cuta(bb,dd) bb.c..dd.c);
  717. label.top(btex$b$etex, cuta(dd,ee) dd.c..ee.c);
  718. label.lrt(btex$a$etex, cuta(dd,bb) dd.c..{dir140}bb.c);
  719. label.bot(btex$a$etex,
  720.   cuta(ee,bb) ee.c..tension1.3 ..{dir115}bb.c);
  721. label.urt(btex$b$etex,
  722.   cuta(ee,cc) ee.c{(cc.c-ee.c)rotated-15}..cc.c);
  723. endfig;
  724. %stopverbatim
  725. The ``boxes'' produced when using \lit{circleit} come out circular unless
  726. something forces a different aspect ratio.\vadjust{\okbreak}
  727. $$ \epsfbox{examples.9} $$
  728. In the above figure, the equations \lit{aa.dx=aa.dy} and \lit{ee.dx=ee.dy} after
  729. $$ \lit{circleit.aa("Start")}
  730.     \quad{\rm and}\quad \lit{circleit.ee("Stop")}
  731. make the start and stop nodes non-circular.
  732. The general rule is that $\lit{bpath.}c$ comes out circular if
  733. $c\lit{.dx}$, $c\lit{.dy}$, and $c\lit{.dx}-c\lit{.dy}$ are all unspecified.
  734. Otherwise the macros select an oval just big enough to contain the given
  735. picture.  (The margin of safety is given by the internal parameter
  736. \lit{circmargin}).
  737. There is also a \lit{pic} macro that makes $\lit{pic.}c$ the picture that
  738. goes inside $\lit{bpath.}c$  In addition to the \lit{drawboxed} macro
  739. that draws the picture and the surrounding rectangle or oval, there are
  740. \lit{drawunboxed} and \lit{drawboxes} macros that draw the pictures and
  741. the surrounding paths separately.
  742. \section{Implementation}
  743. \label{impsec}
  744. The MetaPost interpreter is written in Knuth's {\tt WEB} language which
  745. can be thought of as PASCAL with macros.  This choice allows the
  746. sharing of code with the \MF\ interpreter.~\cite{kn:d}  Indeed, about
  747. three fourths of the code in the main source file {\tt mp.web} is copied
  748. from this source by permission from the author.
  749. In accordance with the standard methodology for {\tt WEB} programs,
  750. parts of the program that are specific to the UNIX\footnote{UNIX is a
  751. registered trademark of UNIX System Laboratories.} system are given in a
  752. separate file {\tt mp.ch} that
  753. the {\tt tangle} processor merges with {\tt mp.web} to form a PASCAL
  754. program.  (It is then automatically translated into C using a
  755. special-purpose translator that is included with the UNIX version
  756. of \TeX.)  The only other code required by the MetaPost interpreter
  757. is a short external C program {\tt mpext.c} and a small include file
  758. {\tt mp.h} to tie it all together.
  759. In addition to the main interpreter, there are some programs that control
  760. the translation of typesetting commands in \lit{btex} $\ldots$ \lit{etex}
  761. blocks.  When the interpreter encounters \lit{btex} in some input file
  762. \lit{foo.mp}, it needs to start reading from an auxiliary file \lit{foo.mpx}.
  763. This file should contain translations of the  \lit{btex} $\ldots$ \lit{etex}
  764. blocks in \lit{foo.mp} into low-level MetaPost commands.  If \lit{foo.mpx} is
  765. out of date or does not exist, the MetaPost interpreter invokes a shell script
  766. that generates the file.
  767. The generation of an auxiliary file \lit{foo.mpx} from an input file
  768. \lit{foo.mp} is a three step process:  a C~program called \lit{mptotex}
  769. strips out the \TeX\ commands; then \TeX\ produces a binary file that
  770. gives low-level typesetting instructions; and finally, a {\tt WEB} program
  771. \lit{dvitomp} writes equivalent MetaPost commands in the \lit{foo.mpx}
  772. file.  When using troff, C~programs \lit{mptotr} and \lit{dmp} replace
  773. \lit{mptotex} and \lit{dvitomp}.
  774. \bibliographystyle{plain}
  775. \bibliography{mpintro}
  776. \end{document}
  777.